package com.simon.hse.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.EditText;

import com.simon.hse.R;
import com.simon.hse.utils.ToastUtils;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

/**
 * 重置密码 -- 弃用 统一web端处理
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity_reset_psd)
public class ResetPsdActivity extends BaseActivity {
    @ViewInject(R.id.et_new_password)
    EditText mEt_new_password;

    @ViewInject(R.id.et_repet_password)
    EditText mEt_repet_password;

    private boolean isShowPsd = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Event(value = {R.id.iv_back, R.id.iv_eye})
    private void clickButton(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finishActivity(ResetPsdActivity.this);
                break;
            case R.id.iv_eye:
                if (!isShowPsd) {// 密码可见
                    isShowPsd = true;
                    mEt_repet_password.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                } else {// 密码不可见
                    isShowPsd = false;
                    mEt_repet_password.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
                break;
        }
    }

    /**
     * 提交
     */
    private void submit() {
        String newPwd = mEt_new_password.getText().toString();
        String repetPwd = mEt_repet_password.getText().toString();
        if (TextUtils.isEmpty(newPwd)) {
            ToastUtils.getInstance().showShortToast("新密码不可为空!");
            return;
        }
        if (TextUtils.isEmpty(repetPwd)) {
            ToastUtils.getInstance().showShortToast("确认密码不可为空!");
            return;
        }
        if (!newPwd.equals(repetPwd)) {
            ToastUtils.getInstance().showShortToast("密码输入不一致，请重新输入!");
            return;
        }

        String[] conditions1 = new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
        String[] conditions2 = new String[]{"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m"};
        String[] conditions3 = new String[]{".", "~", "!", "@", "#", "$", "%", "^", "*"};
        int i = 0;

        for (String condition : conditions1) {
            if (repetPwd.contains(condition)) {
                i++;
            }
        }
        for (String condition : conditions2) {
            if (repetPwd.contains(condition)) {
                i++;
            }
        }
        for (String condition : conditions3) {
            if (repetPwd.contains(condition)) {
                i++;
            }
        }

        if (i <= 1) {
            ToastUtils.getInstance().showShortToast("密码不符合规范!");
            return;
        }


        finishActivity(ResetPsdActivity.this);
        ToastUtils.getInstance().showShortToast(newPwd + " " + repetPwd);
    }
}
